<template>
	<view class="content">
		<view class="title">{{info.title}}</view>
		<view class="newsInfo">
			<image :src="info.avatar" class="avautr"></image>
		  <view class="userInfo">
				<view class="name">{{info.creator}}</view>
				<view class="time">{{info.createdTime}}</view>
			</view>
		</view>
		<view class="newContent" v-html="html"></view>
		<!-- 资讯图片 -->
		<!-- <view class="imgList">
			<image :src="item" class="newsImg" :style="info.mainImg.length >2?'width: 220rpx;':'width: 338rpx;'" v-for="(item,index) in info.mainImg" :key="index"></image>
		</view> -->
	</view>
</template>

<script>
	import { newsDetail } from '../../api/api.js'
	export default {
		data() {
			return {
				// 文章id
				id:'',
				// 文章内容
				info:'',
				// 文章富文本内容
				html:''
			}
		},
		onLoad(e) {
			this.id = e.id
			this.getNewDetail()
		},
		methods: {
			// 获取话题详情
			getNewDetail() {
				let data = {
					id:this.id
				}
				newsDetail(data).then( res=> {
					console.log(res)
					this.info = res.data
					// 将字符串转化为数组赋值
					// this.info.mainImg = this.info.mainImg.split(",")
					var regex = new RegExp('<img ', 'gi')
					this.html = this.info.content.replace(regex, '<img style="width: 100%;" ');
				})
			}
		}
	}
</script>

<style lang="less">
  .content {
		padding: 15rpx 0 30rpx 30rpx;
		.title {
			width: 690rpx;
			font-size: 36rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #353535;
			line-height: 50rpx;
		}
		.newsInfo {
			margin-top: 60rpx;
			display: flex;
			align-items: center;
			.avautr {
				width: 90rpx;
				height: 90rpx;
				border-radius: 50%;
				margin-right: 18rpx;
			}
			.userInfo {
				.name {
					font-size: 28rpx;
					font-family: Helvetica;
					color: #1A1A1A;
					line-height: 34rpx;
				}
				.time {
					font-size: 24rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #808080;
				}
			}
		}
		.newContent {
			margin-top: 30rpx;
			width: 690rpx;
			color: #1A1A1A;
		}
		// 资讯图片
		.imgList {
			margin-top: 20rpx;
			display: flex;
			align-items: center;
			.newsImg {
				width: 220rpx;
				height: 220rpx;
				margin-right: 15rpx;
			}
			.newsImg:nth-child(3) {
				margin-right: 0;
			}
		}
	}
</style>
